//
//  MCLotteryDrawDetailsTableViewCell.m
//  TLYL
//
//  Created by MC on 2017/6/19.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCLotteryDrawDetailsTableViewCell.h"
#import "MCLotteryDrawDetailsCollectionViewCell.h"
#import "MCCollectionViewFlowLayout.h"
#import "MCMineCellModel.h"
@interface MCLotteryDrawDetailsTableViewCell ()
<
UICollectionViewDelegate,
UICollectionViewDataSource
>
/*
 * 彩种期号
 */
@property (nonatomic,strong)UILabel * lab_title;
/*
 * 分隔线
 */
@property (nonatomic,strong)UIView * view_line;

@property (nonatomic,strong) UICollectionView* collectionView;
@property (nonatomic,strong) NSMutableArray*marr_Cell;
@end

@implementation MCLotteryDrawDetailsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

- (void)initView{
    
    self.backgroundColor=[UIColor whiteColor];
    
    /*
     * 彩种期号
     */
    _lab_title =[[UILabel alloc]init];
    _lab_title.textColor=[UIColor grayColor];
    _lab_title.font=[UIFont systemFontOfSize:15];
    _lab_title.text =@"加载中";
    _lab_title.textAlignment=NSTextAlignmentLeft;
    [self  addSubview:_lab_title];
    
    /*
     * 画线
     */
    _view_line=[[UIView alloc]init];
    _view_line.backgroundColor=[UIColor grayColor];
    [self addSubview:_view_line];
    
    
    [self addSubview:self.collectionView];
    
    
    
    _marr_Cell=[[NSMutableArray alloc]init];
    [_marr_Cell    removeAllObjects];
    [self layOutConstraints];
    
    
   
    
}

-(void)layOutConstraints{
    
    [_lab_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.left.equalTo(self.mas_left).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(0);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top).offset(30);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    
    /*
     * 画线
     */
    [_view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_lab_title.mas_left).offset(0);
        make.right.equalTo(self.mas_right).offset(-10);
        make.height.mas_equalTo(0.8);
        make.bottom.equalTo(self.mas_bottom);
    }];
    

}

-(void)setDataSource:(id)dataSource{
    _dataSource=dataSource;
    
    _lab_title.text=@"第2017061909期";
    
    
    if (_marr_Cell.count>0) {
        
    }else{
        
        NSArray * arr_number=@[@"5",@"6",@"8",@"4",@"2"];
        for (int i=0; i<5; i++) {
            CollectionModel * model0=[[CollectionModel alloc]init];
            model0.header_size=CGSizeMake(0, 0);
            model0.item_size=CGSizeMake([MCLotteryDrawDetailsCollectionViewCell computeHeight:nil], [MCLotteryDrawDetailsCollectionViewCell computeHeight:nil]);
            model0.section_color=[UIColor clearColor];
            model0.section_Edge=UIEdgeInsetsMake(10, 50, 0, 0);
            model0.interitemSpacing=0.1;
            model0.lineSpacing=10;
            model0.isHaveHeader=YES;
            model0.id_dentifier=NSStringFromClass([MCLotteryDrawDetailsCollectionViewCell class]);
            /*
             * info
             */
            model0.userInfo=arr_number[i];
            [_marr_Cell addObject:model0];
        }
    }
    
    [self.collectionView reloadData];
}



/*
 * collectionView
 */
-(UICollectionView *)collectionView{
    if (!_collectionView) {
        
        //创建一个layout布局类
        MCCollectionViewFlowLayout * layout = [[MCCollectionViewFlowLayout alloc]init];
        //设置布局方向为横向流布局
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView=[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor=[UIColor clearColor];
        _collectionView.dataSource=self;
        _collectionView.delegate=self;
        [_collectionView registerClass:[MCLotteryDrawDetailsCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([MCLotteryDrawDetailsCollectionViewCell class])];
        
    }
    return _collectionView;
}

#pragma mark - <UICollectionViewDataSource>
// 设置headerView和footerView的
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader) {
        return nil ;
    }
    return nil ;
}
//// 设置section头视图的参考大小，与tableheaderview类似
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
//    BKIntegralCollectionModel * model=self.marr_Cell[section];
//    return model.header_size;
//}
//设置section的颜色
- (UIColor *)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout colorForSectionAtIndex:(NSInteger)section{
    CollectionModel * model=self.marr_Cell[section];
    return model.section_color;
}
//设置item的size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CollectionModel * model=self.marr_Cell[indexPath.section];
    return model.item_size;
}
//设置section的边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    CollectionModel * model=self.marr_Cell[section];
    return model.section_Edge;
}
// 两个cell之间的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    CollectionModel * model=self.marr_Cell[section];
    return model.interitemSpacing;
}
// 两行之间的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    CollectionModel * model=self.marr_Cell[section];
    return model.lineSpacing;
}

//numberOfItemsInSection
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    CollectionModel * model=self.marr_Cell[section];
    if ([model.id_dentifier isEqualToString:NSStringFromClass([MCLotteryDrawDetailsCollectionViewCell class])]) {
        return self.marr_Cell.count;
    }
    return 0;
}

//numberOfSections
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}


//UICollectionViewCell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionViewCell*  cell = nil;
    CollectionModel * model=self.marr_Cell[indexPath.row];
    if (model.id_dentifier) {
        cell =[collectionView dequeueReusableCellWithReuseIdentifier:model.id_dentifier forIndexPath:indexPath];
    }
    if ([model.id_dentifier isEqualToString:NSStringFromClass([MCLotteryDrawDetailsCollectionViewCell class])]) {
        
        MCLotteryDrawDetailsCollectionViewCell *ex_cell=(MCLotteryDrawDetailsCollectionViewCell *)cell;

        ex_cell.dataSource=model.userInfo;
        
    }
    return cell;
}
#pragma mark-didSelect
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    CollectionModel * model=self.marr_Cell[indexPath.section];
    if ([model.id_dentifier isEqualToString:NSStringFromClass([MCLotteryDrawDetailsCollectionViewCell class])]) {
        
        
    }
}




+(CGFloat)computeHeight:(id)info{
    
    return 80;
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
